package com.qcby.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qcby.admin.model.SysRoleMenu;
import com.qcby.admin.dao.SysRoleMenuMapper;
import com.qcby.admin.service.SysRoleMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qcby.framwork.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 角色和菜单关联表 服务实现类
 * </p>
 *
 * @author admin
 * @since 2024-09-01
 */
@Service
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu> implements SysRoleMenuService {
    @Autowired
    private SysRoleMenuMapper roleMenuMapper;
    @Override
    public ResponseResult removeByRoleId(Long id) {
        //构建中间表中与角色id相等的查询条件
        QueryWrapper<SysRoleMenu> queryWrapper=new QueryWrapper();
        queryWrapper.eq("role_id",id);
        //删除所有与角色相关联的菜单项
        int delCount= roleMenuMapper.delete(queryWrapper);
        if(delCount>0){
            return ResponseResult.okResult();
        }
        return ResponseResult.errorResult(500,"没有找到与角色关联的菜单项");
    }
}
